<template>
  <a-switch
          v-model="model"
          :checkedChildren="checkedChildren"
          :unCheckedChildren="unCheckedChildren"
          :disabled="disabled"
          @change="onChange"
          />
</template>
<script>
  export default {
    name: 'RSwitch',
    data () {
      return {
//        model:true,
      }
    },
    props: {
      checkedChildren: {
        type: String,
        default: '是'
      },
      unCheckedChildren: {
        type: String,
        default: '否'
      },
      checkedValue:{
        type: Boolean|String|Number,
        default: true
      },
      unCheckedValue:{
        type: Boolean|String|Number,
        default: false
      },
      formData:{
        type: Object,
        required: true
      },
        disabled:{
        type: Boolean,
        default: false
      },
        field:{
            type: String|Number,
            required: true
        }
    },
    computed:{
        model:{
            get: function () {
                return this.formData[this.field]==this.checkedValue? true: false;
            },
            set: function () {
            }
        }
    },
      watch: {
      },
      created(){
//        this.model = this.formData[this.field]==this.checkedValue? true: false;
      },
    methods: {
      onChange(value){
        this.formData[this.field] = value ? this.checkedValue: this.unCheckedValue;
      }
    },
  }
</script>
<style>

</style>